<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <input type="text" placeholder="请输入答案">
  <button>提交 </button>
  <p></p>
  <script>
    var btn = document.querySelector('button')
    var inp = document.querySelector('input')
    var xhr = new XMLHttpRequest()
    xhr.open('GET', `https://apis.tianapi.com/zimi/index?key=f91ff265d7a7bbed6de9d34babf5abcf`)
    xhr.send()
    xhr.onreadystatechange = function () {
      if (xhr.readyState == 4 && xhr.status == 200) {
        var obj = JSON.parse(xhr.responseText)
        alert('谜题：   ' + obj.result.content)
        btn.onclick = function () {
          if (inp.value == obj.result.answer) {
            alert('正确  ' + '  原因是' + obj.result.reason)
          } else {
            alert('错误')
          }
        }
      }
    }
  </script>
</body>

</html>